//============================================================================
// Name        : Lexon.h
// Author      : lucmir@dcc.ufmg.br
// Description :
//============================================================================

#ifndef __LEXON_H__
#define __LEXON_H__

#include <stdio.h>
#include <string>
#include <iostream>
#include <map>
#include <fstream>
#include <sstream>

#define NOT_IN_VOCABULARY	0

class Lexon {

	public:

		/**
		 *  Inner class for representing vocabulary pair <tf, position>
		 */
		class VocabularyItem {

			unsigned int tf;
			unsigned int position;

			public:

				VocabularyItem(unsigned int tf, unsigned int position)
					: tf(tf), position(position) {
				}

				unsigned int getTf() {
					return this->tf;
				}

				unsigned int getPosition() {
					return this->position;
				}

				void setPosition(unsigned int position) {
					this->position = position;
				}

				void setTf(unsigned int tf) {
					this->tf = tf;
				}

		};

	private:

		// Vocabulary
		std::map<std::string, unsigned int> termIdMap;			// Hash term -> termId
		std::map<unsigned int, VocabularyItem *> vocabulary;	// Hash termId -> <tf, position> in the index
		unsigned int len;										// Number of terms

	public:

		Lexon();
		~Lexon();

		unsigned int contains(std::string term);		// Return the termId or 0
		unsigned int insert(std::string term);
		void insert(std::string term, unsigned int termId);
		unsigned int getLen();
		unsigned int getVocabularyLen();
		unsigned int getTermId(std::string term);
		void setTermId(std::string term, unsigned int termId);

		void vocabularyInsert(unsigned int termId, unsigned int tf, unsigned int pos);
		void vocabularyInsert(unsigned int termId);
		VocabularyItem *vocabularyGetItem(unsigned int termId);
		VocabularyItem *vocabularyGetItem(std::string);
		void setPosition(unsigned int termId, unsigned int pos);
		unsigned int getTermTf(unsigned int termId);
		void incTf(unsigned int termId);

		bool printToFile(std::string vocabularyFileName);
		bool readFromFile(std::string vocabularyFileName);

};

#endif
